package com.xingyi.bacs.controller;

import com.xingyi.bacs.task.SaticScheduleTask;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 用于定义一个切面类，切面类上面需要加上@Component才可以生效
 * Created by wujt on 23/9/2021
 */
@Aspect
@Component
public class AspectController {

    private static final Logger log = LoggerFactory.getLogger(SaticScheduleTask.class);

    /**
     * Pointcut定义定时任务切入点
     */
    @Pointcut("execution(* com.xingyi.bacs.task.SaticScheduleTask.*(..))")
    public void taskAspect(){}

    /**
     * 定时任务日志
     * @param joinPoint
     * @throws Throwable
     */
    @Around("taskAspect()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        String methodName = joinPoint.getSignature().getName();
        String tableName = getTableName(methodName);
        try{
            log.info("********************进入【"+tableName+"】跑批********************");
            long startime = System.currentTimeMillis();
            joinPoint.proceed();
            long endtime = System.currentTimeMillis();
            log.info("********************【"+tableName+"】跑批完成，耗时："+(endtime-startime)+"毫秒********************");
        }catch (Exception e){
            log.info("--------------------【"+tableName+"】跑批发生异常啦，异常内容："+e+"--------------------");
        }
    }

    private String getTableName(String methodName) {
        String returnName = "";
        switch (methodName) {
            case "MerchantTask":
                returnName ="商户信息表（T_BUZ_MERCHANT）";
                break;
            case "SettlementTask":
                returnName ="商户结算表（T_BUZ_SETTLEMENT_DATA）";
                break;
            case "BillTask":
                returnName ="商户挂账表（T_BUZ_BILL_DATA）";
                break;
            case "RJFRAccountInfoTask":
                returnName ="账户结算信息表（RJFR_ACCOUNTINFO）";
                break;
            case "DLRAccountInfoTask":
                returnName ="代理人账户结算信息表（DLR_ACCOUNTINFO）";
                break;
            case "RJAccountSumTask":
                returnName ="跑批结算信息汇总表（RJFR_ACCOUNTSUM）";
                break;
            case "DLRAccountSumTask":
                returnName ="跑批代理人账户汇总表（DLR_ACCOUNTSUM）";
                break;
            case "RjfrTxWaterTask":
                returnName ="提现流水表（RJFR_TX_WATER）";
                break;
            case "RJAccountFlowTask":
                returnName ="账户流水（RJFR_ACCOUNT_FLOW）";
                break;
            case "RJCzFrWaterTask":
                returnName ="充值分润流水跑批表（RJFR_CZFR_WATER）";
                break;
            case "RJCzFxWaterTask":
                returnName ="充值返现流水跑批表（RJFR_CZFX_WATER）";
                break;
            case "RJFyWaterTask":
                returnName ="费用流水表（RJFR_FY_WATER）";
                break;
            case "RJGcWaterTask":
                returnName ="轧差流水表（RJFR_GC_WATER）";
                break;
            case "MJDetailWaterTask":
                returnName ="秒结明细流水（MJ_DETAIL_WATER）";
                break;
            case "TbAccountInfoTask":
                returnName ="同步结算信息表（TB_ACCOUNTINFO）";
                break;
            case "DLRTbAccountInfoTask":
                returnName ="代理人同步结算信息表（DLR_TB_ACCOUNTINFO）";
                break;
            default:
                break;
        }
        return returnName;
    }


}
